﻿using System;
using System.Diagnostics;

namespace Mono.Cecil.PE
{
	// Token: 0x020000F6 RID: 246
	internal sealed class TextMap
	{
		// Token: 0x06000A03 RID: 2563 RVA: 0x00005942 File Offset: 0x00003B42
		public void AddMap(TextSegment segment, int length)
		{
			this.map[(int)segment] = new Range(this.GetStart(segment), (uint)length);
		}

		// Token: 0x06000A04 RID: 2564 RVA: 0x0002DA90 File Offset: 0x0002BC90
		private uint AlignUp(uint value, uint align)
		{
			align -= 1U;
			return value + align & ~align;
		}

		// Token: 0x06000A05 RID: 2565 RVA: 0x0002DAB0 File Offset: 0x0002BCB0
		public void AddMap(TextSegment segment, int length, int align)
		{
			bool flag = segment > TextSegment.ImportAddressTable;
			uint num2;
			if (flag)
			{
				int num = segment - TextSegment.CLIHeader;
				Range range = this.map[num];
				num2 = this.AlignUp(range.Start + range.Length, (uint)align);
				this.map[num].Length = num2 - range.Start;
			}
			else
			{
				num2 = 8192U;
				Debug.Assert(num2 == this.AlignUp(num2, (uint)align));
			}
			Debug.Assert(num2 == this.GetStart(segment));
			this.map[(int)segment] = new Range(num2, (uint)length);
		}

		// Token: 0x06000A06 RID: 2566 RVA: 0x0000595E File Offset: 0x00003B5E
		public void AddMap(TextSegment segment, Range range)
		{
			this.map[(int)segment] = range;
		}

		// Token: 0x06000A07 RID: 2567 RVA: 0x0002DB48 File Offset: 0x0002BD48
		public Range GetRange(TextSegment segment)
		{
			return this.map[(int)segment];
		}

		// Token: 0x06000A08 RID: 2568 RVA: 0x0002DB68 File Offset: 0x0002BD68
		public DataDirectory GetDataDirectory(TextSegment segment)
		{
			Range range = this.map[(int)segment];
			return new DataDirectory((range.Length == 0U) ? 0U : range.Start, range.Length);
		}

		// Token: 0x06000A09 RID: 2569 RVA: 0x0002DBA4 File Offset: 0x0002BDA4
		public uint GetRVA(TextSegment segment)
		{
			return this.map[(int)segment].Start;
		}

		// Token: 0x06000A0A RID: 2570 RVA: 0x0002DBC8 File Offset: 0x0002BDC8
		public uint GetNextRVA(TextSegment segment)
		{
			return this.map[(int)segment].Start + this.map[(int)segment].Length;
		}

		// Token: 0x06000A0B RID: 2571 RVA: 0x0002DC00 File Offset: 0x0002BE00
		public int GetLength(TextSegment segment)
		{
			return (int)this.map[(int)segment].Length;
		}

		// Token: 0x06000A0C RID: 2572 RVA: 0x0002DC24 File Offset: 0x0002BE24
		private uint GetStart(TextSegment segment)
		{
			return (segment == TextSegment.ImportAddressTable) ? 8192U : this.ComputeStart((int)segment);
		}

		// Token: 0x06000A0D RID: 2573 RVA: 0x0002DC4C File Offset: 0x0002BE4C
		private uint ComputeStart(int index)
		{
			index--;
			return this.map[index].Start + this.map[index].Length;
		}

		// Token: 0x06000A0E RID: 2574 RVA: 0x0002DC88 File Offset: 0x0002BE88
		public uint GetLength()
		{
			Range range = this.map[16];
			return range.Start - 8192U + range.Length;
		}

		// Token: 0x04000416 RID: 1046
		private readonly Range[] map = new Range[17];
	}
}
